﻿@inject IHttpService _httpService
@inject NavigationManager NavigationManager

@inject IDataCacheService _dataCacheService


<MMenu OffsetY CloseOnContentClick="false" Value="Menu" ValueChanged="ValueChanged">
    <ActivatorContent Context="m">
        <MTooltip Bottom>
            <ActivatorContent Context="c">
                @{
                    var attrs = new Dictionary<string, object>();
                    m.Attrs.ToList().ForEach(item => attrs[item.Key] = item.Value);
                    c.Attrs.ToList().ForEach(item => attrs[item.Key] = item.Value);
                }
                <MButton Fab Small @attributes="@attrs" Class="@($"cngal-edit-button {Class}")" Color="primary">
                    <MIcon>@IconType.Edit.ToIconString()</MIcon>
                </MButton>
            </ActivatorContent>
            <ChildContent>
                <span>编辑</span>
            </ChildContent>
        </MTooltip>
    </ActivatorContent>

    <ChildContent>
        <MDCard Class="pa-3" Style="@("flex-direction: column; align-items: center; "+(ShowPerfection?"width:350px;":"width:300px;"))">
            <div class="w-100">
                @if (Menu)
                {
                    <EditButtonContent Id="Id" IsEdit="IsEdit" IsHidden="IsHidden" IsHiddenChanged="IsHiddenChanged" IsEditChanged="IsEditChanged" Type="Type" ShowPerfection="ShowPerfection" OnClickExamines="OnClickExamines" OnClickPerfectionInfor="OnClickPerfectionInfor" />
                }
            </div>
        </MDCard>
    </ChildContent>
</MMenu>

<CnGalWebSite.Shared.MasaComponent.PC.EditRecords.EditRecordListCard @ref="editRecordListViewTip" />
<CnGalWebSite.Shared.MasaComponent.PC.Perfections.EntryPerfectionCheckListTip @ref="entryPerfectionCheckListTip" />

@code {
    [Parameter]
    public ExaminedNormalListModelType Type { get; set; }
    [Parameter]
    public long Id { get; set; }
    [Parameter]
    public bool ShowPerfection { get; set; }
    [Parameter]
    public string Class { get; set; }
    [Parameter]
    public bool IsEdit { get; set; }
    [Parameter]
    public bool IsHidden { get; set; }
    [Parameter]
    public EventCallback<bool> IsHiddenChanged { get; set; }
    [Parameter]
    public EventCallback<bool> IsEditChanged { get; set; }

    bool Menu;


    CnGalWebSite.Shared.MasaComponent.PC.EditRecords.EditRecordListCard editRecordListViewTip;
    CnGalWebSite.Shared.MasaComponent.PC.Perfections.EntryPerfectionCheckListTip entryPerfectionCheckListTip;

    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }


    int count = 0;
    public async Task ValueChanged(bool value)
    {
        Menu = value;

        if (value)
        {
            count++;
            await IsEditChanged.InvokeAsync(count % 2 == 1);
        }
        StateHasChanged();
    }

    public void OnClickExamines(List<ExaminedNormalListModel> model)
    {
        if (editRecordListViewTip != null)
        {
            editRecordListViewTip.Refresh(model);
        }
    }

    public async Task OnClickPerfectionInfor(long id)
    {
        if (entryPerfectionCheckListTip != null)
        {
            await entryPerfectionCheckListTip.Refresh(true, id);
        }
    }
}
